package edu.pku.sei.mte.exceptions.handler;

import edu.pku.sei.mte.exceptions.InterruptException;
import edu.pku.sei.mte.exceptions.RetryException;
import edu.pku.sei.mte.runtime.Environment;

public class DefaultExceptionHandler implements ExceptionHandler {

	private Environment env;
	
	public void handle(Exception ex) throws Exception {
		printExceptionInfo(ex);
		interrupt();
	}

	public void interrupt() throws Exception {
		System.err.println("The transformation process of rule instance was interrupted");
		throw new InterruptException();
	}

	public void moveon() throws Exception {
		System.err.println("The transformation process of rule instance moved on");
	}

	public void retry() throws Exception {
		System.err.println("The transformation process of rule instance was retried");
		throw new RetryException();
	}

	public Environment getEnvironment() {
		return env;
	}

	public void setEnvironment(Environment env) {
		this.env = env;
	}

	public void printExceptionInfo(Exception ex) {
		System.err.println("An " + ex.getClass().getSimpleName() + " was thrown out:");
		ex.printStackTrace();
	}

	public void printCustomInfo(String s) {
		System.err.println(s);
	}
}
